const app = require("../app");
const {
  NAME_IS_ALREADY_EXISTS,
  NAME_OR_PASSWORD_IS_REQUIRED,
  NAME_IS_NOT_EXISTS,
  PASSWORD_IS_INCORRENT,
  UNAUTHORIZATION,
} = require("../config/error");
app.on("error", (error, ctx) => {
  let code = 0;
  let message = "";

  switch (error) {
    case NAME_OR_PASSWORD_IS_REQUIRED:
      code = -1001;
      message = "用户名或密码不能为空~";
      break;
    case NAME_IS_ALREADY_EXISTS:
      code = -1002;
      message = "用户名已存在~";
      break;
    case NAME_IS_NOT_EXISTS:
      code = -1003;
      message = "登陆的用户名不存在,请检查~";
      break;
    case PASSWORD_IS_INCORRENT:
      code = -1004;
      message = "密码错误~";
      break;
    case UNAUTHORIZATION:
      code = -1005;
      message = "用户未登录~";
      break;
  }
  ctx.body = { code, msg: message };
});
